--
-- fc_besturen testbench
--

library ieee;
use ieee.std_logic_1164.all;

entity fc_besturen_tb is
end fc_besturen_tb;

architecture testbench of fc_besturen_tb is
	component fc_besturen
		port( 
			switch_L : in		 STD_LOGIC;
			switch_M : in		 STD_LOGIC;
			switch_R : in		 STD_LOGIC;
			divider_ready : in std_logic;
			clk			: in		 STD_LOGIC;
			rst			: in		 STD_LOGIC;
			
			divider_sel : out std_logic_vector(2 downto 0);
			row_req	: out		STD_LOGIC_VECTOR (22 downto 0) := (others => '0');
			trip_start : out std_logic;
			trip_end : out std_logic;
			set_wheelsize : out std_logic;
			wheelsize : out natural range 0 to 28;
			km_counter_start : out std_logic
		);
	end component fc_besturen;
	
	signal clk : std_logic;
	signal rst : std_logic;
	
	signal button_l : std_logic;
	signal button_m : std_logic;
	signal button_r : std_logic;
	
	signal divider_ready : std_logic;
	
	signal divider_sel : std_logic_vector(2 downto 0);
	signal row_req : std_logic_vector(22 downto 0);
	signal trip_start : std_logic;
	signal trip_end : std_logic;
	signal set_wheelsize : std_logic;
	signal wheelsize : natural range 0 to 28;
	signal km_counter_start : std_logic;
	
begin
	clockgen: process is
	begin
		clk <= '1';
		wait for 50 ns;
		clk <= '0';
		wait for 50 ns;
	end process;
	
	datagen: process is
	begin
		-- Test if it goes in the right state when the divider is ready
		rst <= '1';
		button_l <= '0';
		button_r <= '0';
		button_m <= '0';
		divider_ready <= '0';
		
		wait for 200 ns;
		rst <= '0';
		
		wait for 50 ms;
		
		divider_ready <= '1';
		wait for 100 ns;
		
		divider_ready <= '0';
		wait for 10 ns;
		
		wait until clk = '1';
		button_r <= '1';
		wait for 100 ns;
		
		button_r <= '0';
		
		wait for 100 ns;
		divider_ready <= '1';
		wait for 100 ns;
		divider_ready <= '0';
		
		wait for 200 ns;
		
		-- Test if it goes into 'enter_wheelsize' state
		rst <= '1';
		button_l <= '0';
		button_r <= '0';
		button_m <= '0';
		divider_ready <= '0';
		wait for 200 ns;
		
		rst <= '0';
		
		wait for 300 ns;
		
		button_m <= '1';
		wait for 100 ns;
		button_m <= '0';
		
		wait for 300 ns;
		
		button_m <= '1';
		wait for 100 ns;
		button_m <= '0';
		
		wait for 200 ns;
		-- Ok, so if everything's alright, then we should be in the enter_wheelsize state
		button_r <= '1';
		wait for 100 ns;
		button_r <= '0';
		wait for 200 ns;
		
		button_r <= '1';
		wait for 100 ns;
		button_r <= '0';
		wait for 200 ns;
		
		button_r <= '1';
		wait for 100 ns;
		button_r <= '0';
		wait for 200 ns;
		
		button_r <= '1';
		wait for 100 ns;
		button_r <= '0';
		wait for 200 ns;
		
		
		wait;
	end process;
	
	controller: fc_besturen port map (
		clk => clk,
		rst => rst,
		switch_l => button_l,
		switch_m => button_m,
		switch_r => button_r,
		divider_ready => divider_ready,
		divider_sel => divider_sel,
		row_req => row_req,
		trip_start => trip_start,
		trip_end => trip_end,
		set_wheelsize => set_wheelsize,
		wheelsize => wheelsize,
		km_counter_start => km_counter_start
	);

end architecture;
		
